<?php
// 转载请注明出处：https://www.ailingxi.cn/post-2163.html   灵锡资源网
//时间轴编辑
$mod = 'admin';
include('../Common/Core_brain.php');
if($adminData['adminRank']== 2) {
  echo "您的账号没有权限使用此功能";
  exit;
}

$my = isset($_GET['my']) ? $_GET['my'] : null;
$row = [
  'id' => '',
  'timeline_date' => '',
  'title' => '',
  'description' => '',
  'icon' => '',
  'color' => 'primary'
];
if($my == 'edit'){
  $id = intval($_GET['id']);
  $tmp = $DB->getRow("select * from nteam_timeline where id='$id' limit 1");
  if($tmp){
    $row = $tmp;
  }else{
    echo "<script>layer.ready(function(){layer.msg('该履历不存在', {icon: 2, time: 1500}, function(){window.location.href='javascript:history.go(-1)'});});</script>";
    exit;
  }
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <title><?php echo conf('Name');?> - <?php echo $my=='edit'?'编辑':'添加';?>履历</title>
  <link rel="stylesheet" id="css-main" href="../assets/admin/css/codebase.min-5.5.css">
  <link rel="stylesheet" href="../assets/fonts/fontawesome/css/all.min.css">
  <script type="text/javascript" src="../assets/admin/js/jquery.min.js"></script>
  <script src="../assets/layer/layer.js"></script>
  <style>
    .icon-list {
      display: grid;
      grid-template-columns: repeat(4, minmax(80px, 1fr));
      gap: 12px;
      padding: 10px;
      background: #fafbfc;
      border: 1px solid #eee;
      border-radius: 8px;
      margin-top: 8px;
    }
    .icon-item {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      padding: 8px 10px;
      cursor: pointer;
      border-radius: 6px;
      transition: background 0.2s, box-shadow 0.2s;
      font-size: 16px;
    }
    .icon-item:hover {
      background: #f0f4fa;
      box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    }
    .icon-item.selected {
      background: #e3f2fd;
      border: 1.5px solid #2196f3;
    }
    .icon-item i {
      margin-right: 8px;
      font-size: 20px;
    }
  </style>
</head>
<body>
<div id="page-container" class="sidebar-o enable-page-overlay side-scroll page-header-modern main-content-boxed">
<?php require_once 'head.php'; ?>
<main id="main-container">
<div class="content">
  <div class="block block-rounded">
    <div class="block-header block-header-default">
      <h3 class="block-title"><b><?php echo $my=='edit'?'编辑':'添加';?>履历</b></h3>
    </div>
    <div class="block-content">
      <form onsubmit="return saveTimeline(this)" method="post" class="row">
        <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
        <div class="row mb-4">
          <div class="col-6">
            <label class="form-label" for="timeline_date"><b><i class="fa fa-calendar me-1"></i>时间</b></label>
            <input type="date" class="form-control form-control-lg" name="timeline_date" value="<?php echo $row['timeline_date']; ?>" required>
          </div>
          <div class="col-6">
            <label class="form-label" for="title"><b><i class="fa fa-heading me-1"></i>标题</b></label>
            <input type="text" class="form-control form-control-lg" name="title" value="<?php echo $row['title']; ?>" placeholder="请输入标题" required>
          </div>
        </div>
        <div class="mb-4">
          <label class="form-label" for="description"><b><i class="fa fa-align-left me-1"></i>描述</b></label>
          <textarea class="form-control form-control-lg" name="description" rows="3" placeholder="请输入描述" required><?php echo $row['description']; ?></textarea>
        </div>
        <div class="row mb-4">
          <div class="col-6">
            <label class="form-label" for="icon"><b><i class="fa fa-icons me-1"></i>图标</b></label>
            <input type="text" class="form-control form-control-lg" id="icon_input" name="icon" value="<?php echo $row['icon']; ?>" placeholder="请选择或输入图标类名" required>
            <div class="icon-list mt-2" style="max-height:200px;overflow-y:auto;">
              <div class="icon-item<?php if($row['icon']=='fa-rocket')echo ' selected'; ?>" onclick="selectIcon('fa-rocket')"><i class="fa fa-rocket"></i> rocket</div>
              <div class="icon-item<?php if($row['icon']=='fa-cogs')echo ' selected'; ?>" onclick="selectIcon('fa-cogs')"><i class="fa fa-cogs"></i> cogs</div>
              <div class="icon-item<?php if($row['icon']=='fa-image')echo ' selected'; ?>" onclick="selectIcon('fa-image')"><i class="fa fa-image"></i> image</div>
              <div class="icon-item<?php if($row['icon']=='fa-users')echo ' selected'; ?>" onclick="selectIcon('fa-users')"><i class="fa fa-users"></i> users</div>
              <div class="icon-item<?php if($row['icon']=='fa-cube')echo ' selected'; ?>" onclick="selectIcon('fa-cube')"><i class="fa fa-cube"></i> cube</div>
              <div class="icon-item<?php if($row['icon']=='fa-code')echo ' selected'; ?>" onclick="selectIcon('fa-code')"><i class="fa fa-code"></i> code</div>
              <div class="icon-item<?php if($row['icon']=='fa-star')echo ' selected'; ?>" onclick="selectIcon('fa-star')"><i class="fa fa-star"></i> star</div>
              <div class="icon-item<?php if($row['icon']=='fa-check')echo ' selected'; ?>" onclick="selectIcon('fa-check')"><i class="fa fa-check"></i> check</div>
            </div>
          </div>
          <div class="col-6">
            <label class="form-label" for="color"><b><i class="fa fa-palette me-1"></i>图标颜色</b></label>
            <select class="form-select form-select-lg" name="color" required>
              <option value="primary" <?php echo $row['color']=='primary'?'selected':'';?>>蓝色 Primary</option>
              <option value="success" <?php echo $row['color']=='success'?'selected':'';?>>绿色 Success</option>
              <option value="info" <?php echo $row['color']=='info'?'selected':'';?>>青色 Info</option>
              <option value="warning" <?php echo $row['color']=='warning'?'selected':'';?>>橙色 Warning</option>
              <option value="danger" <?php echo $row['color']=='danger'?'selected':'';?>>红色 Danger</option>
              <option value="secondary" <?php echo $row['color']=='secondary'?'selected':'';?>>灰色 Secondary</option>
            </select>
          </div>
        </div>
        <div class="mb-4">
          <button type="submit" class="btn btn-primary">
            <i class="fa fa-check opacity-50 me-1"></i> <b>保存设置</b>
          </button>
          <button type="button" class="btn btn-primary" onclick="javascript:history.back(-1);return false;">
            <i class="fa fa-arrow-right-arrow-left opacity-50 me-1"></i> <b>返回列表</b>
          </button>
        </div>
      </form>
    </div>
  </div>
</div>
</main>
<?php require_once 'foot.php'; ?>
</div>
<script src="../assets/admin/js/codebase.app.min-5.5.js"></script>
<script src="../assets/admin/js/time.js"></script>
<script>
function selectIcon(icon) {
  $('#icon_input').val(icon);
  $('.icon-item').removeClass('selected');
  $(`.icon-item:contains('${icon.replace('fa-','')}')`).addClass('selected');
}

function saveTimeline(obj) {
  var ii = layer.load(2, {shade:[0.1,'#fff']});
  $.ajax({
    type : 'POST',
    url : 'ajax.php?act=saveTimeline',
    data : $(obj).serialize(),
    dataType : 'json',
    success : function(data) {
      layer.close(ii);
      if(data.code == 0){
        layer.alert(data.msg, {icon: 1,closeBtn: false}, function(){window.location.reload()});
      }else{
        layer.alert(data.msg, {icon: 2})
      }
    },
    error:function(data){
      layer.msg('服务器错误');
      return false;
    }
  });
  return false;
}
</script>
</body>
</html> 